<?php
class noticeModel extends model{
	public $base;
	function __construct(&$base){
		parent::__construct($base);
		$this->base=$base;
		$this->table="notice";	
	}
	
	public function sendNotice($data){
		$data['id']=$this->insert($data);
		return $data['id'];
	}
	
	public function deleteNotice($userid,$id){
		$data=$this->selectRow(array("where"=>"id=$id"));
		if($data['userid']==$userid){
			$this->delete("id=$id");
		}
	}
	
	
	/**
	**增加商家通知操作
		$option
			array(
				 
				"content"=>$content,
				"userid"=>$userid,
				
			)
	*/
	public function add($option){
		$content=$option['content'];
		$userid=$option['userid'];
		//发送通知
		$msg=array(
			"dateline"=>time(),
			"type_id"=>1,
			"status"=>0,
			"userid"=>$userid,
			"content"=>sql($content),
		);
		$this->insert($msg);
		 
		//发送推送信息
		
			$pushlist=M("apppush")->select(array(
				"where"=>"  userid=".$userid
			));
			if($pushlist){
				 
				foreach($pushlist as $v){
					$pdata=array(
						"pid"=>$v['id'],
						"typeid"=>1,
						"dateline"=>time(),
						"content"=>removelink($content), 
					);
					M("apppush_plan")->insert($pdata);
				}
			}
		
		//End 推送信息
		
	}
	
}

?>